<template>
  <el-container style="min-height: 100vh">
    <el-aside
      :width="sideWidth + 'px'"
      style="
        background-color: rgb(238, 241, 246);
        box-shadow: 2px 0 6px rgba(0, 21, 41, 0.35);
      "
    >
      <Aside
        :logoTextShow="logoTextShow"
        :isCollapse="isCollapse"
        @select="handleSelect"
      />
    </el-aside>

    <el-container>
      <el-header style="border-bottom: 1px solid #ccc">
        <Header
          :collapseBtnClass="collapseBtnClass"
          :collapse="collapse"
          :user="user"
        />
      </el-header>

      <el-main>
        <!-- 表示当前页面的子路由，会在 router-view 里面展示 -->
        <router-view @refreshUser="getUser"></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
//import request from "@/utils/request";  // this.request 全局挂载
import Aside from "@/components/Aside";
import Header from "@/components/Header";

export default {
  name: "Home",
  data() {
    return {
      collapseBtnClass: "fold",
      isCollapse: false,
      logoTextShow: true,
      sideWidth: 200,
      myIcon: "fold",
      user: {},
    };
  },
  components: {
    Aside,
    Header,
  },
  created() {
    // 从后台获取User数据
    this.getUser();
  },
  methods: {
    handleSelect(index) {
      //console.log(index)
      //console.log(this.$router.options.routes);
    },
    getUser() {
      let username = localStorage.getItem("user")
        ? JSON.parse(localStorage.getItem("user")).username
        : {};
      console.log("username");
      console.log(username);
      // 从后台获取User数据
      this.request.get("/user/username/" + username).then((res) => {
        // 重新赋值最新的后台数据
        this.user = res.data;
        // console.log("this.user.menus");
        // console.log(this.user.menus);
      });
    },
  },
};
</script>

<style>
.el-header {
  color: var(--el-text-color-primary);
  line-height: 60px;
}

.el-aside {
  color: var(--el-text-color-primary);
}
</style>
